//
//  AppDelegate.m
//  XhlTrip
//
//  Created by dllo on 15/8/21.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "AppDelegate.h"
#import "TravelViewController.h"
#import "ToolViewController.h"
#import "StrategyViewController.h"
#import "UMSocial.h"


@interface AppDelegate ()
@property (nonatomic, retain) NSMutableArray *arr;
@property (nonatomic, retain) UIScrollView *scroller;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    TravelViewController *travel = [[TravelViewController alloc] init];
    ToolViewController *tool = [[ToolViewController alloc] init];
    StrategyViewController *strategy = [[StrategyViewController alloc] init];
    
    
    travel.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"游记" image:[self nameWithPath:@"travel.png"] selectedImage:[self nameWithPath:@"travelS.png"]];
    
    strategy.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"攻略" image:[self nameWithPath:@"gonglve.png"] selectedImage:[self nameWithPath:@"gonglveS.png"]];
    
    tool.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"工具" image:[self nameWithPath:@"tool.png"] selectedImage:[self nameWithPath:@"toolS.png"]];
    
   
    
    
    UINavigationController *travelNavi = [[UINavigationController alloc] initWithRootViewController:travel];
    UINavigationController *toolNavi = [[UINavigationController alloc] initWithRootViewController:tool];
    UINavigationController *strategyNavi = [[UINavigationController alloc] initWithRootViewController:strategy];
    
    
    
    NSArray *naviArr = [NSArray arrayWithObjects:travelNavi, strategyNavi, toolNavi, nil];
    UITabBarController *tab = [[UITabBarController alloc] init];
   
    tab.viewControllers = naviArr;
    self.window.rootViewController = tab;
   
    [tab release];
    
    [travel release];
    [strategy release];
    [tool release];
    [toolNavi release];
    [strategyNavi release];
    [travelNavi release];
    
    
    self.arr = [NSMutableArray arrayWithObjects:[self nameWithPath:@"one.png"], [self nameWithPath:@"second.png"], [self nameWithPath:@"three.png"], [self nameWithPath:@"four.png"], nil];

    
#pragma mark - 判断是否为第一次进入
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

    if([userDefaults objectForKey:@"FirstLoad"] == nil) {
        [userDefaults setBool:NO forKey:@"FirstLoad"];
        self.scroller = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];
       self.scroller.backgroundColor = [UIColor whiteColor];
        
        self.scroller.pagingEnabled = YES;
        for (int i = 0; i < [self.arr count]; i++) {
            
            
            UIButton *photoButton = [UIButton buttonWithType:UIButtonTypeSystem];
            
            photoButton.frame = self.scroller.frame;
            
            [photoButton setBackgroundImage:self.arr[i] forState:UIControlStateNormal];
           
            photoButton.backgroundColor = [UIColor redColor];
            photoButton.frame = CGRectMake(self.window.frame.size.width * i, 0, self.window.frame.size.width, self.window.frame.size.height);
            photoButton.userInteractionEnabled = NO;
            [self.scroller addSubview:photoButton];
            
            
            UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
            [self.scroller addSubview:button];
            button.frame = CGRectMake(110 * Width + self.scroller.frame.size.width * i, 555 * Height, 150 * Width, 50 * Height);
            [button addTarget:self action:@selector(backButton:) forControlEvents:UIControlEventTouchUpInside];
            
            
        }
        self.scroller.indicatorStyle = UIScrollViewIndicatorStyleWhite;
        self.scroller.contentSize = CGSizeMake(self.window.frame.size.width * self.arr.count, 0);
        self.scroller.backgroundColor = [UIColor whiteColor];
        [self.window addSubview:self.scroller];
        [_scroller release];
    }
       /**
     *  设置友盟
     */
    [UMSocialData setAppKey:@"55e3f7f967e58ee85b00110d"];
    
    
    
    
    [_window release];
    return YES;
}

- (void)backButton:(UIButton *)button
{
    [self.scroller removeFromSuperview];
}

- (UIImage *)nameWithPath:(NSString *)paths
{
    NSString *path = [[NSBundle mainBundle] pathForResource:paths ofType:nil];
    UIImage *image = [UIImage imageWithContentsOfFile:path];
    return image;
}

- (void)dealloc
{
    [_arr release];
    [_scroller release];
    [_window release];
    [super dealloc];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
